#include "enquete.h"

Enquete::Enquete(int id, QObject *parent) :
    QObject(parent)
{
    QSqlQuery enq;
    enq.exec("SELECT id_camp, nom_camp, descr_camp, debut_camp, fin_camp, client FROM campagnes WHERE id_camp = " + QString::number(id) + ";");
    enq.next();
    if(enq.size() == 1)
    {
        this->id = enq.value(0).toInt();
        this->nom = enq.value(1).toString();
    } // else
        // Trop de questionnaire... ça ne devrait pas arriver ...

    // Récup les questions liées à l'enquête
    QSqlQuery reqQuest;
    reqQuest.exec("SELECT id_quest, num_quest, intitule_quest, lib_nat, nom_camp FROM questions AS q, campagnes AS c, natures AS n WHERE q.campagne = c.id_camp AND q.nature = n.id_nat AND c.id_camp =" + QString::number(this->id) + ";");
    while (reqQuest.next())
    {
        Question *uneQuestion = new Question(reqQuest.value(0).toInt());
        // Stock la question dans la QList
        questions.append(uneQuestion);
    }
}

QString Enquete::getNom() const
{
    return nom;
}

int Enquete::getId() const
{
    return id;
}

void Enquete::setNom(QString newNom)
{
    nom = newNom;
}

QList<Question*> Enquete::getQuestions() const
{
    return questions;
}

QStringList Enquete::getResultatsEnquete() const
{
    return resultatsEnquete;
}

Question* Enquete::getQuestionSuivante() const
{
    return questionSuivante;
}

void Enquete::setQuestionSuivante(Question *newQuestionSuivante)
{
    questionSuivante = newQuestionSuivante;
}
